layui.use(['element', 'layer'], function(){
    var element = layui.element;
    var layer = layui.layer;
    
    //监听折叠
    element.on('collapse(test)', function(data){
      layer.msg('展开状态：'+ data.show);
    });
  });
  layui.use('table', function(){
    var table = layui.table;
    var util = layui.util;
    var key = "";
    table.render({
      elem: '#repair_table'
      ,url:head + '/student/getStudentList'
      ,method:'post'
      ,where:{
        key:key
      }
      ,request: {
        pageName: 'pageNum' //页码的参数名称，默认：page
        ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
      }
      ,toolbar: '#toolbarDemo'
      ,title: '用户数据表'
      ,cols: [[ 
        {field:'studengName', title:'姓名', width:'13%'}
        ,{field:'studentIden', title:'学号', width:'20%'}
        ,{field:'gender', title:'性别', width:'10%', templet:function(d){return getGender(d.gender)}}
        ,{field:'studentAddr', title:'宿舍',width:'42%'}
        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'15%'}
      ]]
      ,page: true
    });
    
    
    //监听行工具事件
    table.on('tool(test)', function(obj){
      var data = obj.data;
      //console.log(obj)
      if(obj.event === 'change'){
        $.ajax({
          url:head+"/student/studentStateChange?id="+data.id,
          type:"POST",
          datatype:"json",
          success:function(redata){
            if(redata.code == 0){
              window.location.reload();
            }else{
              layer.msg(redata.msg,{
                time: 1500
              });
            }
          }
        })
      } else if(obj.event === 'detail'){
        // alert(data.studentiden);
        //弹出层
        layer.open({
          type: 2, 
          title:'学生详细',
          area: ['84%','86%'],
          offset:['5%','8%'],
          scrollbar: true,
          content: 'student_Item.html?id='+data.id,//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
          success: function(layero,index){
          
          }
        }); 
  
      }
    });
  });
  function search(searchStr){

    layui.use('table', function(){
      var table = layui.table;
      var util = layui.util;
      var key = "";
      table.render({
        elem: '#repair_table'
        ,url:head + '/student/getStudentList'+searchStr
        ,method:'post'
        ,request: {
          pageName: 'pageNum' //页码的参数名称，默认：page
          ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        ,toolbar: '#toolbarDemo'
        ,title: '用户数据表'
        ,cols: [[ 
          {field:'studengName', title:'姓名', width:'13%'}
          ,{field:'studentIden', title:'学号', width:'20%'}
          ,{field:'gender', title:'性别', width:'10%', templet:function(d){return getGender(d.gender)}}
          ,{field:'studentAddr', title:'宿舍',width:'42%'}
          ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'15%'}
        ]]
        ,page: true
      });
    });
    
  }